import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import pn_sty from '@dfeidao/fd-w000010';
import p001 from './p001';

export default async function a010(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	const n = e.target as HTMLDivElement;// 使用DIV替换
	const v = n.getAttribute('data-id');
	console.log('vvvvv' + v);// 获取排序字段
	//
	// const m = e.target as HTMLDivElement;
	const u = n.getAttribute('data-flag');
	const ns = fd.data.node.querySelectorAll('[data-asc="desc"]');
	Array.from(ns).forEach((value: HTMLDivElement) => {
		value.setAttribute('class', 'iconfont cursor-p icon-shangxia color-3 font14 pos-a');
	});
	const asc: string[] = [];
	const desc: string[] = [];
	if (u === '1') {
		// 升
		n.setAttribute('data-flag', '0');
		n.setAttribute('class', 'iconfont cursor-p icon-shang color-3 font14 pos-a');
		asc.push(v);
	} else {
		// 降
		n.setAttribute('data-flag', '1');
		n.setAttribute('class', 'iconfont cursor-p icon-xia color-3 font14 pos-a');
		desc.push(v);
	}
	const v1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="select_1"]');
	const v2 = fd.data.node.querySelector<HTMLInputElement>('[data-id="equip_name_1"]');
	const v3 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="select_1"]');
	const pageno = get(fd, 'page-no') as number;
	console.log(pageno);
	if (pageno > 1) {
		const res = await nodejs('device-management-ygh/zj-000002/s001', {
			page: {
				value1: v1.value,
				value2: v2.value,
				value3: v3.value,
				page_no: Number(pageno) || 1,
				asc,
				desc
			}
		});
		console.log(res);
		render(fd, res, p001, 'p001', 'inner');
		const p = fd.data.node.querySelector<pn_sty>('[data-id="p_n"]');
		p.setAttribute('page-no', pageno + '');
	} else {
		const res = await nodejs('device-management-ygh/zj-000002/s001', {
			page: {
				value1: v1.value,
				value2: v2.value,
				value3: v3.value,
				page_no: 1,
				asc,
				desc
			}
		});
		console.log(res);
		render(fd, res, p001, 'p001', 'inner');
	}
}
